package com.Policing.Adapter;

import android.app.Dialog;
import android.content.Context;
import androidx.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.Policing.R;

import java.util.List;

/**
 * Created by Administrator on 2019/5/5.
 */

public class Input_item extends ArrayAdapter {
    private Dialog dialog;
    public Input_item(Context context, int resource, List<com.Policing.bean.Input_Adapter> objects) {

        super(context, resource, objects);
    }

    @Nullable
    @Override
    public Object getItem(int position) {
        return super.getItem(position);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final com.Policing.bean.Input_Adapter linkeMain = (com.Policing.bean.Input_Adapter)getItem(position);
        final View view = LayoutInflater.from(getContext()).inflate(R.layout.input_item, null);
        TextView type_tv = (TextView) view.findViewById(R.id.type_tv);
        ImageView Asset_img = (ImageView)view.findViewById(R.id.Asset_img);
        TextView type = (TextView) view.findViewById(R.id.type);
        TextView model = (TextView)view.findViewById(R.id.model);
        TextView factory_tv = (TextView)view.findViewById(R.id.factory_tv);
        TextView model_tv = (TextView)view.findViewById(R.id.model_tv);
        TextView factory = (TextView)view.findViewById(R.id.factory);
        TextView istag_tv = (TextView)view.findViewById(R.id.istag_tv);
        TextView istag = (TextView)view.findViewById(R.id.istag);
        TextView assetId = (TextView)view.findViewById(R.id.assetId);
        TextView assetNumber = (TextView) view.findViewById(R.id.assetNumber);
        //入库图片
        if(linkeMain.getAsset_img()!=null){
        Asset_img.setImageBitmap(linkeMain.getAsset_img());}
        type_tv.setText(linkeMain.getType_tv());
        type.setText(linkeMain.getType());
        model.setText(linkeMain.getModel());
        factory_tv.setText(linkeMain.getFactory_tv());
        model_tv.setText(linkeMain.getModel_tv());
        factory.setText(linkeMain.getFactory());
        istag_tv.setText(linkeMain.getIstag_tv());
        istag.setText(linkeMain.getIstag());
        assetId.setText(linkeMain.getAssetId());
        assetNumber.setText(linkeMain.getAssetNumber());
            Asset_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //展示在dialog上面的大图
                    if(linkeMain.getAsset_img()!=null) {
                        dialog = new Dialog(getContext(), R.style.FullActivity);
                        WindowManager.LayoutParams attributes = dialog.getWindow().getAttributes();
                        attributes.width = WindowManager.LayoutParams.MATCH_PARENT;
                        attributes.height = WindowManager.LayoutParams.MATCH_PARENT;
                        dialog.getWindow().setAttributes(attributes);
                        ImageView imageView = new ImageView(getContext());
                        imageView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                        imageView.setImageBitmap(linkeMain.getAsset_img());
                        dialog.setContentView(imageView);
                        //大图的点击事件（点击让他消失）
                        dialog.show();
                        imageView.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dialog.dismiss();
                            }
                        });
                    }
                    else {Toast.makeText(getContext(),"没有图片时无法展示大图",Toast.LENGTH_SHORT).show();}
                }
            });

        return view;
    }


}
